package com.zzyl.controller.customer;

import com.aliyun.iot20180120.models.QueryDevicePropertyStatusResponseBody;
import com.zzyl.base.ResponseResult;
import com.zzyl.controller.BaseController;
import com.zzyl.dto.DeviceDto;
import com.zzyl.service.impl.IotServiceImpl;
import com.zzyl.vo.DeviceDataGraphVo;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @className: CustomerUserController
 * @description:
 * @author: 国民老公陈先生
 * @date: 2024/6/15 15:18
 * @Version: 1.0
 */
@RestController
@Slf4j
@RequestMapping("/customer/user")
public class CustomerUserController extends BaseController {
    @Autowired
    private IotServiceImpl iotService;

    /**
     * 查询物模型状态信息
     *
     * @param dto
     * @return
     */
    @PostMapping("/QueryDevicePropertyStatus")
    @ApiOperation(value = "查询物模型状态")
    public ResponseResult QueryDevicePropertyStatus(@RequestBody DeviceDto dto) {
        QueryDevicePropertyStatusResponseBody.QueryDevicePropertyStatusResponseBodyData data = iotService.queryDevicePropertyStatus(dto);
        return success(data);
    }

    /**
     * 按天统计查询指标数据
     * @return
     */
    @GetMapping("/queryDeviceDataListByDay")
    @ApiOperation(value = "按天统计查询指标数据")
    public ResponseResult<List<DeviceDataGraphVo>> queryDeviceDataListByDay(
            @RequestParam(value = "iotId") String iotId,
            @RequestParam(value = "functionId") String functionId,
            @RequestParam(value = "startTime") Long startTime,
            @RequestParam(value = "endTime") Long endTime
    ){
        List<DeviceDataGraphVo> list = iotService.queryDeviceDataListByDay(iotId, functionId, startTime, endTime);
        return success(list);
    }

    /**
     *
     * @param iotId
     * @param functionId
     * @param startTime
     * @param endTime
     * @return
     */
    @GetMapping("/pageQueryAlertData")
    @ApiOperation(value = "按天统计查询指标数据")
    public ResponseResult pageQueryAlertData(
            @RequestParam(value = "iotId") String iotId,
            @RequestParam(value = "functionId") String functionId,
            @RequestParam(value = "startTime") Long startTime,
            @RequestParam(value = "endTime") Long endTime
    ){
        List<DeviceDataGraphVo> list = iotService.queryDeviceDataListByDay(iotId, functionId, startTime, endTime);
        return success(list);
    }

    @GetMapping("/queryDeviceDataListByWeek")
    @ApiOperation(value = "按周统计查询指标数据")
    public ResponseResult<List<DeviceDataGraphVo>> queryDeviceDataListByWeek(
            @RequestParam(value = "iotId") String iotId,
            @RequestParam(value = "functionId") String functionId,
            @RequestParam(value = "startTime") Long startTime,
            @RequestParam(value = "endTime") Long endTime
    ){
        List<DeviceDataGraphVo> list = iotService.queryDeviceDataListByWeek(iotId, functionId, startTime, endTime);
        return success(list);
    }
}
